
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-04-07
 * Time：14:47
 */


package Testdmo4.one;

import java.util.LinkedList;
import java.util.List;

public class TestLinked {

    public static void main(String[] args) {
        List<String> list=new LinkedList<>();

        list.add("钟少爷");
        list.add("郭男神");
        list.add("刘富帅");
        list.add("吴富婆");
        list.add(1,"杰哥哥");

        System.out.println(list);

        System.out.println("====== 删除数据 ========");

        System.out.println(list.remove(3)); // 删除 "刘富帅"
        System.out.println(list.remove(0)); // 删除 "钟少爷"

        System.out.println("======= 获取数据 ========");

        System.out.println(list.get(0));  // "郭男神"
        System.out.println(list.get(1));  // "刘富帅"


        System.out.println("========= 修改数据 =========");
        System.out.println(list.set(0, "彭于晏"));
        System.out.println(list.get(0));


        System.out.println("=========查找数据=========");
        String s=new String("郭男神");
        if (list.contains(s)) {
            System.out.println("该数据的下标为："+ list.indexOf(s));
        } else {
            System.out.println("未找到该数据,查找失败！");
        }
    }
}
